<?php
/*********************************************************************************
 *  PhpStorm - saas
 *-------------------------------------------------------------------------------
 * 版权所有: CopyRight By cw100.com
 * 文件内容简单说明
 *-------------------------------------------------------------------------------
 * $FILE:ShopTrait.php
 * $Author:zxs
 * $Dtime:2017/2/28
 ***********************************************************************************/

namespace App\Http\Traits;

use Illuminate\Support\Facades\Session;
use App\Plugins\Fpage;

trait ShopTrait
{

    /**
     * @param $count
     * @param int    $currentPage
     * @param int    $perPage
     * @param string $pageUrl
     * @param string $str
     * @param bool   $ajax
     * @return string
     * 分页
     */
    public function fPager($count, $currentPage = 0, $perPage = 0, $str = '', $ajax = false)
    {
        $currentPage = $currentPage ? $currentPage : \Request::input('page');
        $url = url(\Request::path()) . ($str ? '?' . $str : '');
        $limit = $perPage ? $perPage : $this->perPage;
        $pager = new Fpage();
        $pageHtml = $pager->pageInit($count, $currentPage, $limit, $url, $ajax)->links();
        if ($count == 0) {
            $pageHtml = '';
        }
        return $pageHtml;
    }



    /**
     * @param $count
     * @param int    $currentPage
     * @param int    $perPage
     * @param string $str
     * @return string
     * 简单分页（专门为shop端商品列表增加的分页样式去掉了'4/21'部分）
     */
    public function simplePageShopList($count, $currentPage = 0, $perPage = 0, $str = '')
    {
        $lastPage = ceil($count / $perPage);
        $currentPage = ($currentPage > $lastPage) ? $lastPage : (($currentPage < 1) ? 1 : $currentPage);
        $url = url(\Request::path()) . ($str ? '?' . $str . '&' : '?');
        $preUrl = $url . 'page=' . ($currentPage == 1 ? 1 : ($currentPage - 1));
        $nextUrl = $url . 'page=' . ($currentPage == $lastPage ? $lastPage : ($currentPage + 1));

        $html = '<p><a href="' .($currentPage == 1 ? 'javascript:;' : $preUrl) . '"'
            . '><i class="iconfont">&#xe6be;</i></a></p>'
            . '<p><a href="' . ($currentPage == $lastPage ? 'javascript:;' : $nextUrl) . '"'
            . '><i class="iconfont">&#xe6bd;</i></a></p>';
        return $html;
    }
}
